package com.nulldev.util.web.nTubeExtensions.Redwood.pages;

import static com.nulldev.util.web.nTubeExtensions.Redwood.Redwood.player;

import com.nulldev.util.JVM.JVM;
import com.nulldev.util.io.file.FileUtil;
import com.nulldev.util.web.HttpServer3.Response;
import com.nulldev.util.web.HttpServer3.pages.v3.HttpPage3;
import com.nulldev.util.web.nTube.resources.project_redwood.RedwoodResource;
import com.nulldev.util.web.nTubeExtensions.Redwood.Redwood;

public class RedwoodBaseFile extends HttpPage3 {

	public RedwoodBaseFile() {
		super("/resources/redwood/youtube_base.js");
		this.setCachingMethod(CachingMethod.SHORT_CACHE);
	}

	@SuppressWarnings("resource")
	@Override
	public Response onRequest(final Request request) {
		if (!Redwood.ENABLE_AUTO_UPDATING)
			return new Response(200, FileUtil.getResourceStream(RedwoodResource.class, "youtube_base.js")).setCustomMime("application/javascript");
		try {
			return new Response(200, createStream(player.getAuto())).setCustomMime("application/javascript");
		} catch (Exception e) {
			JVM.errorln(e);
			return new Response(503);
		}
	}

}
